package freecomm.fileexplorer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.PopupWindow;
import android.widget.SimpleAdapter;

/**  
 * MyOptionMenu  
 *   
 * @author: Junwei.Xu  
 */
public class MyOptionMenu extends PopupWindow
{
    /** the grid view of the option menu */  
    private GridView optionMenuGridView;
    /** the adapter of the grid view */  
    private SimpleAdapter optionMenuAdapter;

      
    /**  
     * create a new object MyOptionMenu.  
     *  
     * @param context  
     */
    public MyOptionMenu(Context context)
    {
        super(context);
        // TODO Auto-generated constructor stub
        String[] mTextArray = context.getResources().getStringArray(R.array.option_menu_text);
        int[] mImageArray = { R.drawable.add_normal, R.drawable.choose_normal,
                R.drawable.size_normal };
        List<Map<String, Object>> optionItemList = new ArrayList<Map<String, Object>>();
        Map<String, Object> mAddMap;

        for (int i = 0; i < 3; i++)
        {
            mAddMap = new HashMap<String, Object>();
            mAddMap.put(FileExplorer.LIST_ITEM_TEXT_MAP_KEY, mTextArray[i]);
            mAddMap.put(FileExplorer.LIST_ITEM_IMG_MAP_KEY, mImageArray[i]);
            optionItemList.add(mAddMap);
        }
        optionMenuAdapter = new SimpleAdapter(context, optionItemList,
                R.layout.option_menu_item, new String[] {
                        FileExplorer.LIST_ITEM_TEXT_MAP_KEY,
                        FileExplorer.LIST_ITEM_IMG_MAP_KEY }, new int[] {
                        R.id.option_menu_item_text, R.id.option_menu_item_img });

        
        View mView = View.inflate(context, R.layout.option_menu, null);
        optionMenuGridView = (GridView) mView
                .findViewById(R.id.option_menu_grid);
        optionMenuGridView.setAdapter(optionMenuAdapter);
        this.setContentView(mView);
        this.setWidth(LayoutParams.FILL_PARENT);
        this.setHeight(LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
    }
    
    /**  
     * set the item click event listener of the grid view
     * @param mListener  - the item click event listener  
     * @return void  
     * @exception   
    */
    public void setGridViewItemClickListener(OnItemClickListener mListener){
        optionMenuGridView.setOnItemClickListener(mListener);
    }
}
